<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('用户基本信息列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
    <div class="ui-layout-west" th:if="${showFlag}">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i> 组织机构
                </div>
                <div class="box-tools pull-right">
                    <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新部门"><i class="fa fa-refresh"></i></button>
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>
    <div class="ui-layout-center">
         <div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse" th:if="${showFlag}">
                    <form id="formId">
                        <input type="hidden" id="deptId" name="deptId">
                        <div class="select-list">
                            <ul>
                                <li>
                                    <label>工号：</label>
                                    <input type="text" name="userNo"/>
                                </li>
                                <li>
                                    <label>姓名：</label>
                                    <input type="text" name="name"/>
                                </li>
                                <li>
                                    <label>性别：</label>
                                    <select name="sex" th:with="type=${@dict.getType('sys_user_sex')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li>
                                    <label>用户类别：</label>
                                    <select name="userType" th:with="type=${@dict.getType('basic_user_type')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li>
                                    <label>技术类别：</label>
                                    <select name="technicalType" th:with="type=${@dict.getType('basic_user_technical')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li>
                                    <label>岗位属性：</label>
                                    <select name="postType" th:with="type=${@dict.getType('post_type')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li class="select-time">
                                    <label>来院时间： </label>
                                    <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
                                    <span>-</span>
                                    <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>

                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="basic:user:add">
                        <i class="fa fa-plus"></i> 添加
                    </a>
                    <a class="btn btn-primary single disabled" onclick="$.operate.editFull()" shiro:hasPermission="basic:user:edit">
                        <i class="fa fa-edit"></i> 修改
                    </a>
                    <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="basic:user:remove">
                        <i class="fa fa-remove"></i> 删除
                    </a>
                    <a class="btn btn-danger multiple disabled" onclick="syncUser()" shiro:hasPermission="basic:user:sync">
                        <i class="fa fa-remove"></i> 同步用户
                    </a>
                    <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="basic:user:import">
                        <i class="fa fa-upload"></i> 导入
                    </a>
                    <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="basic:user:export">
                        <i class="fa fa-download"></i> 导出
                    </a>
                </div>
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('basic:user:edit')}]];
        var removeFlag = [[${@permission.hasPermi('basic:user:remove')}]];
        var prefix = ctx + "basic/user";

        var sexs = [[${@dict.getType('sys_user_sex')}]];
        var types = [[${@dict.getType('basic_user_type')}]];
        var nations = [[${@dict.getType('basic_user_nation')}]];
        var healths = [[${@dict.getType('basic_user_health')}]];
        var politicals = [[${@dict.getType('basic_user_political')}]];
        var attends = [[${@dict.getType('attend_type')}]];
        var posts = [[${@dict.getType('post_type')}]];
        var positions = [[${@dict.getType('basic_user_position')}]];
        var technicals = [[${@dict.getType('basic_user_technical')}]];
        var depts = [[${@dict.getType('basic_user_dept')}]];

        $(function() {
            var panehHidden = false;
            if ($(this).width() < 769) {
                panehHidden = true;
            }
            $('body').layout({ initClosed: panehHidden, west__size: 185 });
            // 回到顶部绑定
            if ($.fn.toTop !== undefined) {
                var opt = {
                    win:$('.ui-layout-center'),
                    doc:$('.ui-layout-center')
                };
                $('#scroll-up').toTop(opt);
            }
            queryUserList();
            queryDeptTree();
        });

        function queryUserList() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/importData",
                importTemplateUrl: prefix + "/importTemplate",
                modalName: "用户基本信息",
                pageSize: 15,
                pageList: [15, 30, 50],
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键id',
                    visible: false
                },
                {
                    title: "序号",
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
                {
                    field: 'userNo',
                    title: '工号',
                    sortable: true
                },
                {
                    field: 'name',
                    title: '姓名'
                },
                {
                    field: 'sex',
                    title: '性别',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(sexs, value);
                    }
                },
                {
                    field: 'nationType',
                    title: '民族',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(nations, value);
                    }
                },
                {
                    field: 'phonenumber',
                    title: '手机号码'
                },
                {
                    field: 'idCard',
                    title: '身份证号'
                },
                {
                    field: 'deptName',
                    title: '所属部门',
                    sortable: true
                },
                {
                    field: 'userType',
                    title: '用户类别',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(types, value);
                    }
                },
                {
                    field: 'userPosition',
                    title: '职位类别',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(positions, value);
                    }
                },
                {
                    field: 'userDept',
                    title: '管理科室',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(depts, value);
                    }
                },
                {
                    field: 'politicalType',
                    title: '政治面貌',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(politicals, value);
                    }
                },
                {
                    field: 'healthStatus',
                    title: '健康状况',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(healths, value);
                    }
                },
                {
                    field: 'technicalType',
                    title: '技术类别',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(technicals, value);
                    }
                },
                {
                    field: 'attendType',
                    title: '考勤分类',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(attends, value);
                    }
                },
                {
                    field: 'postType',
                    title: '岗位属性',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(posts, value);
                    }
                },
                {
                    field: 'holdWork',
                    title: '社会兼职情况'
                },
                {
                    field: 'politicalTime',
                    title: '组织时间',
                    sortable: true
                },
                {
                    field: 'hospitalTime',
                    title: '来院时间',
                    sortable: true
                },
                {
                    field: 'leaveTime',
                    title: '离院时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        }

        function queryDeptTree()
        {
            var url = ctx + "system/dept/treeData";
            var options = {
                url: url,
                expandLevel: 1,
                onClick : zOnClick
            };
            $.tree.init(options);

            function zOnClick(event, treeId, treeNode) {
                $("#deptId").val(treeNode.id);
                $.table.search();
            }
        }

        $('#btnExpand').click(function() {
            $._tree.expandAll(true);
            $(this).hide();
            $('#btnCollapse').show();
        });

        $('#btnCollapse').click(function() {
            $._tree.expandAll(false);
            $(this).hide();
            $('#btnExpand').show();
        });

        $('#btnRefresh').click(function() {
            queryDeptTree();
        });

        /**
         * 同步用户
         */
        function syncUser(){
            var rows = $.table.selectFirstColumns();
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.ajax({
                url: prefix + "/syncUser",
                type: "post",
                dataType: "json",
                data: {"userIds" : rows.join() },
                beforeSend: function () {
                    $.modal.loading("正在同步中，请稍候...");
                    $.modal.disable();
                },
                success: function(result) {
                    $.operate.successCallback(result);
                }
            });
        }
    </script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <div class="mt10 pt5">
                    <select name="updateType">
                        <option value="1">更新用户数据</option>
                        <option value="2">更新日期数据</option>
                    </select>
                </div>
            </div>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果用户信息已经存在，更新这条数据。"> 是否更新已经存在的用户数据
                &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>